<template>
    <div class="process-monitoring-box">
        <commpVxeTable
         :config="dataTableConfig" 
         :columns="columnsVxe" 
         :formItem="formItem"
         ref="acceptanceRegistrationRef"
         >
            <template v-slot:fsxmc_name="{row}" data-desc="自定操作栏">
                <span v-if="row.fzwxtbzzt == '补正中'" class="fsxmcQ-c-t">[{{ row.fzwxtbzzt}}]</span>
                <span v-if="row.fzwxtbzzt == '已补正'" class="fsxmcQ-l-t">[{{ row.fzwxtbzzt}}]</span>

                <span v-if="row.fzwxtzgzt == '整改中'" class="fsxmcQ-c-t">[{{ row.fzwxtzgzt }}]</span>
                <span v-if="row.fzwxtzgzt == '已整改'" class="fsxmcQ-l-t">[{{ row.fzwxtzgzt }}]</span>

                <span v-if="row.fzwxtcjzt == '撤件回复'" class="fsxmcQ-h-t" @click="cjhfClick()">[{{ row.fzwxtcjzt }}]</span>
                <span v-if="row.fzwxtcjzt == '撤件审核中'" class="fsxmcQ-c-t">[{{ row.fzwxtcjzt }}]</span>
                <span v-if="row.fzwxtcjzt == '已撤件'" class="fsxmcQ-l-t">[{{ row.fzwxtcjzt }}]</span>

                <span v-if="row.fzwxtthzt" class="fsxmcQ-h-t">{{ row.fzwxtthzt }}</span>
                <a v-if="row.fsxmc" href="#" @click="viewingMattersClick(row)">{{ row.fsxmc }}</a>
            </template>
         <template v-slot:name_fslsj="{row}" data-desc="自定操作栏">
            <span>{{ timeProcessing(row.fslsj) }}</span>
        </template>
        <template v-slot:name_ffssj="{row}" data-desc="自定操作栏">
            <span>{{ row.ffssj }}</span>
        </template>
        <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
            <a-form layout="inline" class="search-form" >
                <a-form-item >
                    <a-button class="blue-btn" type="primary" @click="handleClick(row)">办理</a-button>
                </a-form-item>
            </a-form>
        </template>
        </commpVxeTable>
        <increase
         ref="refModel" 
         :addEditParameter="addEditParameter" 
         @successReturn="successReturn" 
         @flowPathTwoSuccess="successReturn" 
         :flowPath2="flowPath2"
         @handleClick="handleClick"
         />
        <viewDealWith ref="dealWithRef" :addEditParameter="addEditParameter" />
    </div>
</template>
<script>
import viewDealWith from './viewDealWith.vue'
import assessCheckApi from './service/api'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import increase from './increase.vue'
import moment from 'moment'
import {
    queryJobByJobIdServe,
    queryAllYbJob,
    querySqsxDetailsById,
    getSqsxBm,
} from './service/index'
import blobType from '@/common/blobType'
export default {
    components:{
        commpVxeTable,
        increase,
        viewDealWith,
    },
    props:{

    },
    data(){
        return{
            addEditParameter:{},
            flowPath2:{},
            formItem:[
                {
                    label: '事项名称',
                    model: 'fsxmc',
                },{
                    label: '企业名称',
                    model: 'fqymc',
                },{
                    label: '申请单号',
                    model: 'fsqdbh',
                },{
                    label: '任务编号',
                    model: 'fslbh',
                },{
                    label: '环节名称',
                    model: 'fhjmc',
                    placeholder: '环节名称',
                    type:'Select',
                    dictionaryType:'查验流程环节名称'
                }

            ],
            columnsVxe:[
            { 
                type: 'checkbox', 
                width: 60 ,
                fixed: 'left'
            },{
                title: '事项名称', //列头显示文字
                field: 'fsxmc',
                slots: {
                    default: 'fsxmc_name',
                },
                fixed: 'left',
            },{
                title: '企业名称', //列头显示文字
                field: 'fqymc',
            },{
                    title: '申请单号',
                    field: 'fsqdbh',
            },{
                title: '任务编号',
                field: 'fslbh',
            },{
                title: '接收时间',
                field: 'fslsj',
                slots: {
                    // 使用插槽模板渲染
                    default: 'name_fslsj',
                },
            },{
                title: '剩余天数',
                field: 'syday',
                width:60,
            },{
                title: '环节名称',
                field: 'fhjmc',
            },{
                title: '待办人',
                field: 'fdbr',
            },{
                title: '发送人',
                field: 'ffsrmc',
            },{
                title: '发送时间',
                field: 'ffssj',
                slots: {
                    // 使用插槽模板渲染
                    default: 'name_ffssj',
                },
            },{
                    title: '操作',
                    field: 'id',
                    slots: {
                        // 使用插槽模板渲染
                        default: 'operation_btn',
                    },
                    fixed: 'right',
                    width:120,
            }],
            dataTableConfig:{
                api: assessCheckApi.list,
                rowId: 'jobid',
                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                paramet:{
                }
            },
        }
    },
    watch:{

    },
    mounted(){
        
    },
    methods:{
        cjhfClick(){
            this.$route.push('/enterpriseWithdrawalApplication/index')
        },
        timeProcessing(val){
            if(val){
                val = val.slice(0,11)
            }
            return val
        },
        handleClick(val){
            let that = this
            queryJobByJobIdServe({jobid:val.jobid}).then(res=>{
                //console.log('办理',res)
                if(res.code == 200){
                    let fthyjOptions = []
                    queryAllYbJob({jobid:val.jobid}).then(res2=>{
                        if(res2.code == 200){
                            //console.log(res2)
                            res2.result.forEach(item=>{
                                fthyjOptions.push({value:item.id,label:item.fhjmc})
                            })
                            let data = res.result.sqsx
                            that.addEditParameter = {
                                // isReadOnly:true,
                                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                                jobid:res.result.job.id,
                                sqsxid:data.id,
                                fsxmc:data.fsxmc,
                                fhjmc:res.result.job.fhjmc,
                                fsqsj:data.fsqsj?moment(data.fsqsj).format('YYYY-MM-DD'):'',
                                fjclx:data.fjclx,
                                fslzt:String(data.fslzt),
                                fslsj:data.fslsj?moment(data.fslsj).format('YYYY-MM-DD'):'',
                                fslbh:data.fslbh,
                                fwcsx:data.fwcsx,
                                fjzrq:data.fjzrq,

                                fqyid:data.fqyid,//企业Id
                                fqymc:data.fqymc,
                                ftyshxydm:data.ftyshxydm,
                                fqyfddbrfzr:data.fqyfddbrfzr,
                                fqylxr:data.fqylxr,
                                fqylxrdh:data.fqylxrdh,
                                fqyzszcdz:data.fqyzszcdz,
                                fszdq:data.fszdq,
                                fxxdz:data.fxxdz,

                                fcpmc:data.fcpmc,//产品名称
                                fsqdbh:data.fsqdbh,
                                fspdwmc:data.fspdwmc,
                                fbldwmc:data.fbldwmc,
                                ffsr:data.ffsr,
                                ffssj:data.ffssj,
                                fblr:data.fblr,
                                dbrid:[],
                                opinion:'',//办理意见
                                smgflag:false,//是否发送短信
                                dbridRequired:true,
                                fthyj:res.result.job.fthyj,//退回意见
                                fthyjOptions:fthyjOptions,
                                shjid:fthyjOptions.length?fthyjOptions[0].value:'',
                                fthyjInput:'',
                                fblzt:res.result.job.fblzt,
                                fqyjbxx:data.fqyjbxx,
                                fcyjcfw:data.fcyjcfw,
                                fjcsjjrcap:data.fjcsjjrcap,
                                fcjryjjczfz:data.fcjryjjczfz,
                                fjcxm:data.fjcxm,
                                fjcfajqtyq:data.fjcfajqtyq,
                                fcyjcyj:data.fcyjcyj,
                                ...res.result.qy,
                            }
                            that.flowPath2 = {
                                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                                jobid:res.result.job.id,
                                sqsxid:data.id,
                                fscms:data.fscms?data.fscms:'技术审评',
                                fcykssj:data.fcykssj,
                                fcyjssj:data.fcyjssj,
                                fcyhbqy:data.fcyhbqy?data.fcyhbqy.split(','):data.fcyhbqy,
                                fcyxzqy:data.fcyxzqy,
                                fcyzytc:data.fcyzytc?data.fcyzytc.split(','):data.fcyzytc,
                                timeArr:data.fcykssj?[data.fcykssj,data.fcyjssj]:[],
                                nextNodeDbrList:res.result.nextNodeDbrList,
                                nextNode:res.result.nextNode,
                                dbrid:res.result.nextNodeDbrList.length == 1?[res.result.nextNodeDbrList[0].dbrid]:[],
                                opinion:'',//办理意见
                                smgflag:false,//是否发送短信
                                fcyfazt:data.fcyfazt,
                                fspfazt:data.fspfazt,
                                fhjmc:res.result.job.fhjmc,

                                //技术
                                fsphbqy:data.fsphbqy?data.fsphbqy.split(','):data.fsphbqy,
                                fspxzqy:data.fspxzqy,
                                fspkssj:data.fspkssj,
                                fspjssj:data.fspjssj,
                                spTimeArr:data.fspkssj?[data.fspkssj,data.fspjssj]:[],
                                fspzytc:data.fspzytc?data.fspzytc.split(','):data.fspzytc,
                                spDbrid:res.result.nextNodeDbrList.length == 1?[res.result.nextNodeDbrList[0].dbrid]:[],
                                spOpinion:'',//办理意见
                                spSmgflag:false,//是否发送短信
                                fthyj:res.result.job.fthyj,//退回意见
                                fthyjOptions:fthyjOptions,
                                shjid:fthyjOptions.length?fthyjOptions[0].value:'',
                                fthyjInput:'',
                                fblzt:res.result.job.fblzt,
                                fqyjbxx:data.fqyjbxx,
                                fcyjcfw:data.fcyjcfw,
                                fjcsjjrcap:data.fjcsjjrcap,
                                fcjryjjczfz:data.fcjryjjczfz,
                                fjcxm:data.fjcxm,
                                fjcfajqtyq:data.fjcfajqtyq,
                                fcyjcyj:data.fcyjcyj,
                                ...res.result.qy,
                                
                                
                            }
                            
                            this.$refs.refModel.getData(this.addEditParameter)
                            this.$refs.refModel.visibleShow = true
                        }
                    })
                }else{
                    this.$message.warning(res.message)
                }
            })
        },
        viewingMattersClick(val){
            //console.log(val)
            querySqsxDetailsById({sqsxid:val.sqsxid}).then(res=>{
                //console.log(res)
                if(res.code == 200){
                    let data = res.result.sqsx
                    getSqsxBm({sqsxid:data.id}).then(res2=>{
                        if(res2.code == 200){
                            this.addEditParameter = {
                                sqsxbm:res2.result,
                                dbridRequired:true,
                                // isReadOnly:true,
                                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                                // jobid:res.result.job.id,
                                // fblzt:res.result.job.fblzt,
                                // fthyj:res.result.job.fthyj,
                                jobid:val.jobid,
                                sqsxid:data.id,
                                fsxmc:data.fsxmc,
                                fsqsj:data.fsqsj?moment(data.fsqsj).format('YYYY-MM-DD'):'',
                                fjclx:data.fjclx,
                                fslzt:String(data.fslzt),
                                fslsj:data.fslsj?moment(data.fslsj).format('YYYY-MM-DD'):'',
                                fslbh:data.fslbh,
                                fwcsx:data.fwcsx,
                                fjzrq:data.fjzrq,

                                fqyid:data.fqyid,//企业Id
                                fqymc:data.fqymc,
                                ftyshxydm:data.ftyshxydm,
                                fqyfddbrfzr:data.fqyfddbrfzr,
                                fqylxr:data.fqylxr,
                                fqylxrdh:data.fqylxrdh,
                                fqyzszcdz:data.fqyzszcdz,
                                fszdq:data.fszdq,
                                fxxdz:data.fxxdz,

                                fcpmc:data.fcpmc,//产品名称
                                fsqdbh:data.fsqdbh,
                                fspdwmc:data.fspdwmc,
                                fbldwmc:data.fbldwmc,
                                ffsr:data.ffsr,
                                ffssj:data.ffssj,
                                fblr:data.fblr,
                                dbrid:[],
                                opinion:'',//办理意见
                                smgflag:false,//是否发送短信
                                fsxjclx:data.fsxjclx,
                                ...res.result.qy,
                            }
                            this.$refs.dealWithRef.visibleShow = true
                            this.$refs.dealWithRef.spinning = true
                            this.$aSpinningKey = true
                            this.$refs.dealWithRef.getData(this.addEditParameter)
                        }else{
                            this.$message.warning(res2.message)
                        }
                    })
                }else{
                    this.$message.warning(res.message)
                }
            })
            
            
        },
        successReturn(){
            this.$refs.acceptanceRegistrationRef.searchEvent()
        },
    }
}
</script>